//
//  CBGEvaluationViewController.m
//  chebabaGYS
//
//  Created by yisu on 15/12/28.
//  Copyright © 2015年 zhengminjie. All rights reserved.
//

#import "CBGEvaluationViewController.h"
#import "CustomDefine.h"
#import "RatingBar.h"

@interface CBGEvaluationViewController ()<RatingBarDelegate>{

    UIImageView *touxiangimg;
    UILabel *phoneLabel;
    UIImageView *oneStar;
    UIImageView *twoStar;
    UIImageView *threeStar;
    UIImageView *fourStar;
    UIImageView *fiveStar;
    UILabel *xxxxlabel; //xxx单
    
    UIButton *phoneBtn; //有电话图标的button
    UIButton *messgeBtn; //有信息图标的button
    
    UIView *lineView; //评价用户的线
    UILabel *evalab;    //用户评价的Label
    UIView *starView;   //评价用户的星星
    
    UILabel *whylabel1;  //原因1Label
    UILabel *whylabel2;  //原因2Label
    UILabel *whylabel3;  //原因3Label
    UIButton *whyBtn1;  //取消原因Button1
    UIButton *whyBtn2;  //取消原因Button2
    UIButton *whyBtn3;  //取消原因Button3
    
    UITextView *textViewContent; // 评价的内容
    UIButton *queding_Btn;  //确定的按钮
}
@property (strong, nonatomic)   UIView *bottomView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSString *numberStar;
@end

@implementation CBGEvaluationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self buildpage]; //搭建视图
    [self markStarShine]; //使星星亮起
    // Do any additional setup after loading the view.
}
- (void)buildpage{

    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, __kWidth, __kHeight)];
    _scrollView.contentSize = CGSizeMake(__kWidth, 700);
    _scrollView.scrollEnabled = YES;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, __kWidth, 700)];
    [_scrollView addSubview:_bottomView];
    
    touxiangimg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
    touxiangimg.image = [UIImage imageNamed:@"Head "];
    //touxiangimg.backgroundColor = [UIColor redColor];
    [_bottomView addSubview:touxiangimg];
    
    phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectOrigin(touxiangimg).x +5 + CGRectW(touxiangimg), 20, 100, 20)];
    phoneLabel.font = [UIFont systemFontOfSize:14];
    phoneLabel.text = @"01234567899";
    [_bottomView addSubview:phoneLabel];
    
    oneStar = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectOrigin(touxiangimg).x +5+CGRectW(touxiangimg), CGRectY(phoneLabel) +CGRectH(phoneLabel) , 10, 10)];
    oneStar.image = [UIImage imageNamed:@"xingxing02"];
    [_bottomView addSubview:oneStar];
    
    twoStar = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectOrigin(oneStar).x+1 + CGRectW(oneStar), CGRectY(phoneLabel) +CGRectH(phoneLabel) , 10, 10)];
    twoStar.image = [UIImage imageNamed:@"xingxing02"];
    [_bottomView addSubview:twoStar];
    
    threeStar = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectOrigin(twoStar).x+1+CGRectW(twoStar), CGRectY(phoneLabel) +CGRectH(phoneLabel) , 10, 10)];
    threeStar.image = [UIImage imageNamed:@"xingxing02"];
    [_bottomView addSubview:threeStar];
    
    fourStar = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectOrigin(threeStar).x+1+CGRectW(threeStar), CGRectY(phoneLabel) +CGRectH(phoneLabel) , 10, 10)];
    fourStar.image = [UIImage imageNamed:@"xingxing02"];
    [_bottomView addSubview:fourStar];
    
    fiveStar = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectOrigin(fourStar).x+1+CGRectW(fourStar), CGRectY(phoneLabel) +CGRectH(phoneLabel) , 10, 10)];
    fiveStar.image = [UIImage imageNamed:@"xingxing02"];
    [_bottomView addSubview:fiveStar];
    
    xxxxlabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectOrigin(touxiangimg).x +5+CGRectW(touxiangimg), CGRectY(oneStar) +CGRectH(oneStar), 100, 20)];
    xxxxlabel.text = @"xxxxxx单";
    xxxxlabel.font = [UIFont systemFontOfSize:14];
    [_bottomView addSubview:xxxxlabel];
    
    phoneBtn = [[UIButton alloc] initWithFrame:CGRectMake(__kWidth - 20 - 30, 30, 30, 30)];
    [phoneBtn setImage:[UIImage imageNamed:@"weixiuzhong_05"] forState:UIControlStateNormal];
    [phoneBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    phoneBtn.tag = 1;
    [_bottomView addSubview:phoneBtn];
    
    messgeBtn = [[UIButton alloc] initWithFrame:CGRectMake(__kWidth - 20 - 30 - 5 - 30, 30, 30, 30)];
    [messgeBtn setImage:[UIImage imageNamed:@"weixiuzhong_03"] forState:UIControlStateNormal];
    [messgeBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    messgeBtn.tag = 2;
    [_bottomView addSubview:messgeBtn];

    lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectY(touxiangimg) + 20 + CGRectH(touxiangimg), __kWidth, 1)];
    lineView.backgroundColor = [UIColor grayColor];
    [_bottomView addSubview:lineView];
    
    evalab = [[UILabel alloc] initWithFrame:CGRectMake(__kWidth / 2  - 35, CGRectY(lineView)- 10, 70, 20)];
    evalab.textColor = [UIColor grayColor];
    evalab.text = @"用户评价";
    evalab.backgroundColor = [UIColor whiteColor];
    [_bottomView addSubview:evalab];
    
    starView = [[UIView alloc] initWithFrame:CGRectMake(__kWidth / 2  - 35, CGRectY(evalab) + CGRectH(starView) + 20, 100, 40)];
    [_bottomView addSubview:starView];
    
    whylabel1 = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectY(starView) + CGRectH(starView),  200, 20)];
    whylabel1.text  = @"1.计划有变,已和师傅电话沟通";
    whylabel1.font = [UIFont systemFontOfSize:14];
    [_bottomView addSubview:whylabel1];
    
    whylabel2 = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectY(whylabel1) + CGRectH(whylabel1) + 10,  200, 20)];
    whylabel2.text  = @"2.维修效果不满意";
    whylabel2.font = [UIFont systemFontOfSize:14];
    [_bottomView addSubview:whylabel2];

    whylabel3 = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectY(whylabel2) + CGRectH(whylabel2) + 10,  200, 20)];
    whylabel3.text  = @"3.其他";
    whylabel3.font = [UIFont systemFontOfSize:14];
    [_bottomView addSubview:whylabel3];
    
    whyBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(__kWidth - 20-20, CGRectY(whylabel1)+5, 10, 10)];
    [whyBtn1 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
    whyBtn1.tag = 3;
    [whyBtn1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:whyBtn1];
    
    whyBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(__kWidth - 20-20, CGRectY(whylabel2)+5, 10, 10)];
    [whyBtn2 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
    whyBtn2.tag = 4;
    [whyBtn2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:whyBtn2];
    
    whyBtn3 = [[UIButton alloc] initWithFrame:CGRectMake(__kWidth - 20-20, CGRectY(whylabel3)+5, 10, 10)];
    [whyBtn3 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
    whyBtn3.tag = 5;
    [whyBtn3 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:whyBtn3];
    
    textViewContent = [[UITextView alloc] initWithFrame:CGRectMake(20, CGRectY(whylabel3) + CGRectH(whylabel3)+10, __kWidth - 40, 150)];
    textViewContent.text = @"请输入评价内容";
    textViewContent.layer.borderColor = UIColor.grayColor.CGColor;
    textViewContent.layer.borderWidth = 1;
    textViewContent.layer.cornerRadius = 5;
    textViewContent.layer.masksToBounds = YES;
    [_bottomView addSubview:textViewContent];
    
    queding_Btn = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectY(textViewContent) + CGRectH(textViewContent)+10, __kWidth - 40, 30)];
    queding_Btn.tag = 6;
    [queding_Btn setImage:[UIImage imageNamed:@"button06"] forState:UIControlStateNormal];
    [queding_Btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:queding_Btn];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.view endEditing:YES];
}


- (void)buttonAction:(UIButton *)button{

    if (button.tag == 1) {
        NSLog(@"打电话");
    }
    if (button.tag == 2) {
        NSLog(@"信息");
    }
    if (button.tag == 3) {
        NSLog(@"原因1");
        [whyBtn1 setImage:[UIImage imageNamed:@"quxiaoDD_06"] forState:UIControlStateNormal];
        [whyBtn2 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
        [whyBtn3 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
    }

    if (button.tag == 4) {
        NSLog(@"原因2");
        [whyBtn1 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
        [whyBtn2 setImage:[UIImage imageNamed:@"quxiaoDD_06"] forState:UIControlStateNormal];
        [whyBtn3 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
    }

    if (button.tag == 5) {
        NSLog(@"原因3");
        [whyBtn1 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
        [whyBtn2 setImage:[UIImage imageNamed:@"quxiaoDD_03"] forState:UIControlStateNormal];
        [whyBtn3 setImage:[UIImage imageNamed:@"quxiaoDD_06"] forState:UIControlStateNormal];
    }
    if (button.tag == 6) {
        NSLog(@"确定提交");
    }


}


//使星星亮起来
- (void)markStarShine{
    
    CGFloat width = 100 + 35;
    CGFloat height = 40;
    
    CGFloat x = (starView.bounds.size.width - width)*0.5;
    RatingBar *ratingBar = [[RatingBar alloc] initWithFrame:CGRectMake(x, 0, width, height)];
    [starView addSubview:ratingBar];
    //是否是指示器
    ratingBar.isIndicator = NO;
    
    [ratingBar setImageDeselected:@"xzwxc_13" halfSelected:nil fullSelected:@"xzwxc_14" andDelegate:self];
    
}

#pragma mark - RatingBar delegate
- (void)ratingChanged:(float)newRating{
    self.numberStar = [NSString stringWithFormat:@"%.0f",newRating];
    NSLog(@"self.starScroe---------%@", self.numberStar);
}


- (IBAction)backBtnAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
